<template>
	<view>
		<view @tap="back(item)" class="box" v-for="item in list" :key="item.id">
			<view class="left">
				<view class="name">
					<view >
						{{item.name}}
					</view>
					<view class="default" v-if="item.defaultStatus">
						默认
					</view>
				</view>
				<view class="number">
					{{item.phoneNumber}}
				</view>
				
			</view>
			<view class="right" @tap="go(item.id)">
				<image src="/static/icons/xgdz.png" mode=""></image>
			</view>
		</view>

		<view class="new" @tap="go(1)">
			新增地址
		</view>
	</view>
</template>

<script>
	import {
		findAllAddress
	} from "@/api/mine/mine.js"
	export default {
		data() {
			return {
				list: [],
				type:''
			}
		},
		onShow() {
			this.getList()
		},
		onLoad(a) {
			this.getList()
			this.type = a.type
		},
		methods: {
			getList() {
				findAllAddress().then(res => {
					console.log(res)
					this.list = res.data.items
				})
			},
			go(val){
				if(val == 1){
					uni.navigateTo({
						url:"/pages/mine/address/add"
					})
				}else{
					uni.navigateTo({
						url:`/pages/mine/address/edit?id=${val}`
						
					})
				}
				
			},
			back(val){
				console.log(this.type)
				if(this.type == 'select'){
					uni.setStorageSync("area",val)
					uni.navigateBack({
						delta:1
					})
				}else{
					return
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 90%;
		box-sizing: border-box;
		height: 150rpx;
		line-height: 50rpx;
		display: flex;
		margin: 0 auto;
		justify-content: space-between;
		align-items: center;
		padding: 40rpx 0rpx;
		border-bottom: 2rpx solid #ccc;

		.left {
			.name {
				font-size: 28rpx;
				display: flex;
				align-items: center;
			}

			.number {
				font-size: 24rpx;
				color: #999;
			}
		}

		.right {
			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.new {
		width: 70%;
		height: 80rpx;
		border-radius: 80rpx;
		background-color: #354e44;
		color: #fff;
		line-height: 80rpx;
		text-align: center;

		margin: 500rpx auto;
	}

	.default {
		width: 80rpx;
		height: 32rpx;
		font-size: 22rpx;
		background-color: #354e44;
		color: #fff;
		border-radius: 4rpx;
		line-height: 32rpx;
		text-align: center;
		margin-left: 30rpx;
	}
</style>
